{include file='public/header' /}
<style type="text/css">
        .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
        .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
        .header button{float: right;margin-top: -5px;}
    </style>
</head>
<body style="padding: 10px;">
    <div class="header">
        <span>菜单管理</span>
        <div></div>
    </div>
    <form class="layui-form" style="margin-top: 10px;">
        <div class="layui-form-item">
            {if condition="$mid>0"}
            <button class="layui-btn layui-btn-primary layui-btn-sm" style="float: right;margin:5px 0px;" onclick="back({$backid});return false;">返回上级</button>
            {/if}
            <input type="hidden" name="id" value="{$mid}">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>排序</th>
                    <th>菜单名称</th>
                    <th>controller</th>
                    <th>method</th>
                    <th>是否隐藏</th>
                    <th>是否禁用</th>
                    <th>----</th>
                </tr>
                </thead>
                <tbody>
                {volist name="menus" id='menus'}
                <tr>
                    <td>{$menus.mid}</td>
                    <td><input type="text" class="layui-input" name="ords[{$menus.mid}]" value="{$menus.ord}"></td>
                    <td><input type="text" class="layui-input" name="titles[{$menus.mid}]" value="{$menus.title}"></td>
                    <td><input type="text" class="layui-input" name="controller[{$menus.mid}]" value="{$menus.controller}"></td>
                    <td><input type="text" class="layui-input" name="method[{$menus.mid}]" value="{$menus.method}"></td>
                    <td><input type="checkbox" name="ishidden[{$menus.mid}]" lay-skin="switch" lay-text="显示|隐藏" {$menus.ishidden=='1'?'':'checked'} value={$menus.ishidden}></td>
                    <td><input type="checkbox" name="status[{$menus.mid}]" lay-skin="switch" lay-text="正常|禁用" {$menus.status=='1'?'':'checked'} value={$menus.status}></td>
                    <td><button class="layui-btn layui-btn-xs" onclick="child({$menus.mid});return false;">子菜单</button></td>
                </tr>
                {/volist}
                <tr>
                    <td></td>
                    <td><input type="text" class="layui-input" name="ords[0]"></td>
                    <td><input type="text" class="layui-input" name="titles[0]"></td>
                    <td><input type="text" class="layui-input" name="controller[0]"></td>
                    <td><input type="text" class="layui-input" name="method[0]"></td>
                    <td><input type="checkbox" name="ishidden[0]" lay-skin="switch" lay-text="显示|隐藏" value=1></td>
                    <td><input type="checkbox" name="status[0]" lay-skin="switch" lay-text="正常|禁用" value=1></td>
                    <td></td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
    </div>
    <button class="layui-btn " onclick="save()">保存</button>
</body>
</html>
<script type="text/javascript">
    layui.use(['layer','form'],function(){
        $ = layui.jquery;
        layer = layui.layer;
        form = layui.form;
    });

    // 子菜单
    function child(mid){
        window.location.href="__PUBLIC__/admin/menu/index?mid="+mid;
    }

    // 返回上一级
    function back(mid){
        window.location.href="__PUBLIC__/admin/Menu/index?mid="+mid;
    }

    //保存
    function save(){
        //console.log($('form').serialize());
        //jq方法serialize（）将表单值序列化，创建 URL 编码文本字符串。a=1&b=2&c=3&d=4&e=5
        $.post('__PUBLIC__/admin/menu/save',$('form').serialize(),function(res){
            if(res.code>0){
                layer.alert(res.msg,{'icon':2});
            }else{
                layer.msg(res.msg,{'icon':1});
                setTimeout(function(){window.location.reload();},1000);
            }
        },'json');
    }
</script>